<?php 
	require '../../global.php';
	$id = $_POST['id'];
	$name = $_POST['name'];
	if(empty($id)){
		header("Location: /tool/index.php");
		exit;
	}
	if(empty($name)){
		header("Location: /tool/index.php?id={$id}");
		exit;
	}
	
	$body = $_POST['body'];
	if(!file_exists(ROOT.'/external/widgets/'.$id)){
		header("Location: /tool/index.php?id={$id}");
		exit;
	}
	$file = ROOT.'/external/widgets/'.$id.'/'.$name.'widget.html';
	if(file_exists($file)){
		header("Location: /tool/index.php?id={$id}");
		exit;
	}
	create_file($file,$body);
	header("Location: /tool/index.php?id={$id}");